package com.kaifamiao.sorted;

import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

/**
 * NavigableMap首先是一个有顺序的Map，其实是个可导航的Map
 */
public class NavigableMapTest {

    public static void main(String[] args) {

        /*
        NavigableMap<Integer,String> map = new TreeMap<>();

        map.put( 88, "老碗鱼" );
        map.put( 99, "鱼香茄子" );
        map.put( 77, "鱼香肉丝" );
        map.put( 12, "麻婆豆腐" );
        System.out.println( map );

        System.out.println( map.lowerEntry( 80 ) );
        System.out.println( map.higherEntry( 80 ) );
        */

        NavigableMap<String,Integer> map = new TreeMap<>();
        map.put( "鱼香茄子", 14 );
        map.put( "鱼香肉丝", 14 );
        map.put( "麻婆豆腐", 10 );
        map.put( "优质牛肉面" , 16 );
        System.out.println( map );

        Map.Entry<String,Integer> first = map.firstEntry();
        System.out.println( first.getKey() + ":" + first.getValue() );

        System.out.println( map.lastEntry() );

        System.out.println( map.lowerEntry( "麻婆豆腐" ) );
        System.out.println( map.higherEntry( "鱼香肉丝" ) );

        System.out.println( map.lowerEntry( "鱼香" ) );
        System.out.println( map.higherEntry( "鱼香" ) );
    }

}
